home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk2.zip / LST13-17.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  2KB  |  93 lines

  1. ;
  2. ; *** Listing 13-17 ***
  3. ;
  4. ; Copies a zero-terminated string to another string,
  5. ; filtering out non-printable characters by means of a
  6. ; macro that performs the test.
  7. ;
  8.     jmp    Skip
  9. ;
  10. SourceString    label    byte
  11.     db    'This is a sample string, consisting of '
  12. X=1
  13.     rept    31
  14.     db    X
  15. X=X+1
  16.     endm
  17.     db    7fh
  18.     db    'both printable and non-printable '
  19.     db    'characters', 0
  20. DestinationString    label    byte
  21.     db    200 dup (?)
  22. ;
  23. ; Macro that determines whether a character is printable (in
  24. ; the range 20h through 7Eh).
  25. ;
  26. ; Input:
  27. ;    AL = character to check
  28. ;
  29. ; Output:
  30. ;    Zero flag set to 1 if character is printable,
  31. ;        set to 0 otherwise
  32. ;
  33. ; Registers altered: none
  34. ;
  35. IS_PRINTABLE    macro
  36.     local    IsPrintableDone
  37.     cmp    al,20h
  38.     jb    IsPrintableDone    ;not printable
  39.     cmp    al,7eh
  40.     ja    IsPrintableDone    ;not printable
  41.     cmp    al,al    ;set the Zero flag to 1, since the
  42.             ; character is printable
  43. IsPrintableDone:
  44.     endm
  45. ;
  46. ; Copies a zero-terminated string to another string,
  47. ; filtering out non-printable characters.
  48. ;
  49. ; Input:
  50. ;    DS:SI = source string
  51. ;    ES:DI = destination string
  52. ;
  53. ; Output: none
  54. ;
  55. ; Registers altered: AL, SI, DI
  56. ;
  57. ; Direction flag cleared
  58. ;
  59. ; Note: Does not handle strings that are longer than 64K
  60. ;    bytes or cross segment boundaries.
  61. ;
  62. CopyPrintable:
  63.     cld
  64. CopyPrintableLoop:
  65.     lodsb            ;get the next byte to copy
  66.     IS_PRINTABLE        ;is it printable?
  67.     jnz    NotPrintable    ;nope, don't copy it
  68.     stosb            ;put the byte in the
  69.                      ; destination string
  70.     jmp    CopyPrintableLoop ;the character was
  71.                 ; printable, so it couldn't
  72.                 ; possibly have been 0. No
  73.                 ; need to check whether it
  74.                 ; terminated the string
  75. NotPrintable:
  76.     and    al,al        ;was that the
  77.                 ; terminating zero?
  78.     jnz    CopyPrintableLoop ;no, do next byte
  79.     stosb            ;copy the terminating zero
  80.     ret            ;done
  81. ;
  82. Skip:
  83.     call    ZTimerOn
  84.     mov    di,seg DestinationString
  85.     mov    es,di
  86.     mov    di,offset DestinationString
  87.             ;ES:DI points to the destination
  88.     mov    si,offset SourceString
  89.             ;DS:SI points to the source
  90.     call    CopyPrintable    ;copy the printable
  91.                 ; characters
  92.     call    ZTimerOff
  93.